cmake_minimum_required(VERSION 3.14)

project(snipocr LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
#set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "F:/DevelopmentKit/cmakeFind")

# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check https://doc.qt.io/qt/deployment-android.html for more information.
# They need to be set before the find_package(...) calls below.

#if(ANDROID)
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
#    if (ANDROID_ABI STREQUAL "armeabi-v7a")
#        set(ANDROID_EXTRA_LIBS
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
#    endif()
#endif()

message("cmake build type ${CMAKE_BUILD_TYPE}")
message("CMAKE_SYSTEM_NAME ${CMAKE_SYSTEM_NAME}")
message("PROJECT_SOURCE_DIR" ${PROJECT_SOURCE_DIR})
#message("CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}")

find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Widgets Quick LinguistTools REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Widgets Quick LinguistTools REQUIRED)

include_directories(
    ${PROJECT_SOURCE_DIR}/
    ${PROJECT_SOURCE_DIR}/utils
    )

if (CMAKE_SYSTEM_NAME MATCHES "Windows")
    message("link windows library")
    include_directories(
        F:/DevelopmentKit/log4cplus/vs2019_64/include
        )

    link_directories(
        F:/DevelopmentKit/log4cplus/vs2019_64/lib
        )
elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
elseif (CMAKE_SYSTEM_NAME MATCHES "Linux")
endif ()

#get_property(dirs DIRECTORY PROPERTY link_directories)
#get_property(dirs DIRECTORY PROPERTY LINK_DIRECTORIES)
#foreach(dir ${dirs})
#  message(STATUS "dir='${dir}'")
#endforeach()

aux_source_directory(./utils UTILS_SRC)
aux_source_directory(. MAIN_SRC)

set(HEADER_FILES
    ./constant.h
    ./snipapplication.h
    ./utils/sniptools.h)

set(TS_FILES snipocr_zh_CN.ts)

set(PROJECT_SOURCES
        main.cpp
        qml.qrc
        ${TS_FILES}
        ${UTILS_SRC}
        ${MAIN_SRC}
        ${HEADER_FILES}
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(snipocr
        ${PROJECT_SOURCES}
    )

    qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
else()
    if(ANDROID)
        add_library(snipocr SHARED
            ${PROJECT_SOURCES}
        )
    else()
        if (CMAKE_SYSTEM_NAME MATCHES "Windows")
            message("current build windows")
            add_executable(snipocr
              ${PROJECT_SOURCES}
            )

            target_link_libraries(snipocr
                PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick Qt${QT_VERSION_MAJOR}::Widgets
                debug log4cplusUD.lib
                debug log4cplusqt5debugappenderUD.lib
                optimized log4cplusU.lib
                optimized log4cplusqt5debugappenderU.lib)

            target_compile_definitions(snipocr
              PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)

        elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
        elseif (CMAKE_SYSTEM_NAME MATCHES "Linux")
        endif ()
    endif()

    qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
endif()

